package lanou.giftsay_01.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import lanou.giftsay_01.R;
import lanou.giftsay_01.bean.CategoryBean;

/**
 * Created by dllo on 16/8/22.
 */
public class LanmuAdapter extends BaseAdapter {
 private   Context context ;
 private CategoryBean categoryBean ;

    public void setCategoryBean(CategoryBean categoryBean) {
        this.categoryBean = categoryBean;
        notifyDataSetChanged();
    }

    public LanmuAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return categoryBean != null ? categoryBean.getData().getColumns().size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
             ViewHolder viewHolder = null ;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_lanmulv , parent ,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.title.setText(categoryBean.getData().getColumns().get(position).getTitle());
        viewHolder.update.setText(categoryBean.getData().getColumns().get(position).getSubtitle());
        viewHolder.author.setText(categoryBean.getData().getColumns().get(position).getAuthor());
        Picasso.with(context).load(categoryBean.getData().getColumns().get(position).getCover_image_url()).into(viewHolder.iv);
        return convertView;
    }


    private class ViewHolder {
        TextView title ;
        ImageView iv ;
        TextView update ;
        TextView author ;

        public ViewHolder( View view) {
            title = (TextView) view.findViewById(R.id.tv_title_lanmulv);
            iv = (ImageView) view.findViewById(R.id.iv_item_lanmulv);
            update = (TextView) view.findViewById(R.id.tv_gengxin_lanmulv);
            author = (TextView) view.findViewById(R.id.tv_zuozhe_lanmulv);
        }
    }
}
